package initialize

import (
	"context"
	"github.com/go-redis/redis/v8"
	"go.uber.org/zap"
	"strconv"
	"virtual-resource-schedule-service/global"
)

func InitializeRedis() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     global.ServerConfig.RedisConfig.Host + ":" + strconv.Itoa(global.ServerConfig.RedisConfig.Port),
		Password: global.ServerConfig.RedisConfig.Password,
		DB:       global.ServerConfig.RedisConfig.DB,
	})

	// 测试Redis连接
	pong, err := rdb.Ping(context.TODO()).Result()
	if err != nil {
		zap.S().Infof("连接Redis失败: %v", err)
		return
	}
	zap.S().Infof("连接Redis成功: %s", pong)
	global.RedisClient = rdb
}
